package com.atguigu.sparkcore.rdd.tranformsinglevale

import com.atguigu.sparkcore.util.MySparkContextUtil
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * rdd转换-map
  */
object Map {

  def main(args: Array[String]): Unit = {

    // 获取sparkContext
    val sc = MySparkContextUtil.get(args)

    // 创建rdd
    val list: Array[Int] = Array(2, 3, 4, 1, 7)
    val rdd: RDD[Int] = sc.makeRDD(list, 2)

    // 转换rdd
    val result: RDD[Int] = rdd.map(w => {
      w * 2
    })

    // 输出
    result.collect().foreach(println)

    // 关闭资源
    MySparkContextUtil.close(sc)
  }

}
